package ru.spbu.mm.diploma.server.dao;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import ru.spbu.mm.diploma.common.entity.Userrole;

import java.util.List;

/**
 *
 */
public class UserroleDAOImpl extends HibernateDaoSupport implements IUserroleDAO {
    public Userrole getUserroleWithId(Integer id) {
        return (Userrole) this.getHibernateTemplate().get(Userrole.class, id);
    }

    public Userrole getUserroleWithDescription(String description) {
        Userrole obj = null;
        DetachedCriteria criteria = DetachedCriteria.forClass(Userrole.class);
        criteria.add(Restrictions.like("description", description));
        List objs = getHibernateTemplate().findByCriteria(criteria);
        if ((objs != null) && (objs.size() > 0)) {
            obj = (Userrole) objs.get(0);
        }
        return obj;
    }

    public List<Userrole> getUserroles() {
        return (List<Userrole>) this.getHibernateTemplate().loadAll(Userrole.class);
    }
}
